title = "分类详情页"
url = '/:slug|[a-z0-9\-]+-c-\d+.html$'
title = '分类详情页模板'
layout = 'default'
==
use Jason\Ccshop\Controllers\Filters;
use Jason\Ccshop\Controllers\Categories;
use Jason\Ccshop\Models\Category;
use Jason\Ccshop\Models\Product;
function onStart(){
    $slugArr = explode('-', str_replace('.html','', $this->param('slug')));
    $slug = str_replace(array('price_asc-','price_desc-', 'popular_desc-', 'newness_desc-'), array(), $this->param('slug'));
    $id = array_pop($slugArr);
    array_pop($slugArr);
    $condition = ['id' => $id];

    $this['paramKey'] = join('-', $slugArr);
    $categoryModel = Category::where('id', $id)->first();

    $this['currentUrl'] = str_replace(array('price_asc-','price_desc-', 'popular_desc-', 'newness_desc-'), array(), substr(request()->getRequestUri(),1));
    $this['sortFlag'] = $slugArr[0];

    if(!$categoryModel) {
        return redirect('/404');
    }
    $this['category'] = $categoryModel;

    $pids = get('id_sort')?get('id_sort'):null;
    $pageNumber = get('page')?get('page'):1;

    if(!empty($pids)){
        Cookie::queue('idssort',$pids);
        Cookie::queue('cid',$id);
        Cookie::queue('pagenumber',$pageNumber);
    }else{
        $pageNumber = Cookie::get('pagenumber');
        $cid = Cookie::get('cid');
        $currentPage = get('page')?get('page'):1;
        if($currentPage==$pageNumber && $id==$cid){
            $pids = Cookie::get('idssort');
        }
    }

    if (!empty($pids)) {
        $pida = explode(',',$pids);
        $pd = Product::InStock()->whereIn('id',$pida)->get();
        $this['adproducts'] = $pd;
        $this['pida'] = $pida;
    }

    if ($this['paramKey'] != $categoryModel['slug']) {
        $paramKey = explode('-',$this['paramKey']);
        $orderArr = Filters::parseFilterKeyParams($paramKey[0]);
    if (count($orderArr) == 2) {
        $order = [$orderArr[0] => $orderArr[1]];
    }
}

$this['order'] = isset($order) ? $order : ['sort' => 'asc'];
$this['products'] = App::make('Jason\Ccshop\Controllers\Products')->getCategoryProducts($categoryModel->id, $this['order']);

}
==

{% put page_title %}{{ category.page_title }}{% endput %}
{% put meta_keywords %}{{ category.meta_keywords }}{% endput %}
{% put meta_description %}{{ category.meta_description }}{% endput %}

{% for key, product in products.data %}
  {% put google_tag_params %}
  var google_tag_params = {
    ecomm_prodid: "{{product.id}}",
    ecomm_pagetype: "category",
    ecomm_totalvalue: {{product.price|ratePrice}}
  };
  {% endput %}
{% endfor %}
<div class="category_content">
		<!-- breadcrumbs -->
		<!-- breadcrumbs end -->
		<div class="categoryCont">
			<div class="container">
				{% partial 'catalog/category-sidebar' products=products %}
				<div class="fr rightBox">
					{% partial 'catalog/ad-products' adproducts=adproducts %}
					<div class="catg_rightBoxTop boxSizing">
						<div class="fl">
							<button class="fiveShow" dataClass="fiveShow"><i class="fa fa-th"></i></button>
							<button class="threeShow active" dataClass="threeShow"><i class="fa fa-th-large"></i></button>
						</div>
						{% partial 'catalog/category-paging' %}
						
					</div>
					{% partial 'catalog/list-toolbar' %}

					<div class="catg_productBox">
						<ul class="catg_product ">
							{% for product in products.data %}
								<li class="catgItem">
									<a href="{{ product.url }}" title="{{ product.name }}">
									

										<div class="catgItem_image ">
											<img  class="lazy " data-original="{{ product.f_thumb }}" alt="{{ product.name }}" width="100%">
											<!--{% if product.saled > 500 %}
											<span class="hotSale sale_"><img src="{{ 'assets/img/hotSale.png'|theme }}" alt=""></span>
											{% endif %}-->

											{% if product.labels == "newest" %}
											<span class="newSale sale_"><img src="{{ 'assets/img/newSale.png'|theme }}" alt=""></span>
											{% endif %}
											
											{% if sortFlag=="newness_desc" %}
											<span class="new_catrgory">
												<!--<img src="{{ 'assets/img/new_catrgory.png'|theme }}" alt="">-->
												<span class="new_catrgory_span">new</span>
											</span>
											{% endif %}
										</div>
										<div class="catgItem_data">
											<p class="omit"></p>
											<p class="omit">{{ product.name }}</p>
											<p class="omit" style="line-height: 25px;">
												<span style="color: #eb7859;">{{ product.price|formatPrice }} 税込</span>
												{% if product.discount %}
													<span class="product_discount">-{{ product.discount }}</span>
												{% endif %}
											</p>
											<p class="omit">
												<!--<span class="reviewStar size2 star{{ product.rating }}"></span>-->
												{% if product.reviews_total %}
												<a href="{{ product.url }}?rel={{ list }}#reviews" class="reviewsShow">レビュー / <b>{{ product.reviews_total }}</b> 件</a>
												{% endif %}
											</p>
										</div>
									</a>
									
								</li>
							{% endfor %}

						</ul>	
					</div>
					<div class="catg_rightBoxTop boxSizing">
						{% partial 'catalog/category-paging' %}
					</div>
				</div>
			</div>
		</div>
	</div>
